<template>
	<view>
		<view class="cflex-c u-m-20">
			<view class="u-flex " style="align-items: center;justify-content: center;">
				<image style="height: 342rpx;width: 764rpx;" src="../../static/qianBao/big.png"></image>
			</view>
			<view class="cflex-c" style="justify-content: center;align-items: center;z-index: 100;">
				<view style="margin-top: -362rpx;color: #FFFFFF;font-size: larger;">
					当前余额（元）
				</view>
				<view style="color: #FFFFFF;font-size:40px;padding-top: 30rpx;">
					{{data}}
				</view>
			</view>
		</view>

		<view class="cflex-r u-m-20" style="justify-content: space-between;">
			<view class="cflex-r">
				<view>
					<image src="../../static/qieTu/shu.png" style="width: 4px;height: 20px;"></image>
				</view>
				<view class="u-p-l-10">我要提现</view>
			</view>

			<view>
				<view style="color: #FFBB01;margin-right: 20rpx;" @tap="goBill()">查看账单</view>
				<view style="border: 1rpx solid #FFBB01;width: 110rpx;"></view>
			</view>
		</view>


		<view class="cflex-r u-m-20">
			<view class="cbg-white cflex-c" style="border-radius: 25rpx 0 0 25rpx;height: 92rpx;
			width: 526rpx;align-items: center;justify-content: center;">
				<view class="u-m-b-10" style="font-size:medium;">
					<input class="u-p-l-20 u-font-16" v-model="money" placeholder="输入提现金额" maxlength="10" type="digit"
						 />
				</view>

			</view>
			<view class="cflex-c" style="width: 224rpx;height: 92rpx;align-items: center;justify-content: cen;"
				@tap="anyMoney()">
				<view style="z-index: 1;">
					<image src="../../static/qianBao/small_1.png" style="width: 224rpx;height: 92rpx;"></image>
				</view>
				<view style="font-weight: bold;margin-top: -80rpx;z-index: 100;color: #FFFFFF;font-size: larger;">
					立即提现
				</view>
			</view>
		</view>
		<u-gap height="280" bg-color="rgb(246,247,248)" v-show="showGap"></u-gap>
		<view class="u-m-20 u-m-t-80 u-m-b-80" style="font-size: small;color: #aaaaaa;
		line-height:50rpx;">
			<view>注意事项</view>
			<view>1.提现的本金不能少于20元。</view>
			<view>2.本平台所提现金额收取8%培训费。</view>
		</view>




	</view>
</template>

<script>
	var jWeixin
	export default {
		data() {
			return {
				// #ifdef APP-PLUS
				showWeiXin: true,
				// #endif
				// #ifdef MP-WEIXIN
				showWeiXin: false,
				// #endif


				data: '',
				money: '',
				type: 0, //充值方式 1微信 2支付宝
				typeName: '',

				show: false,
				id: 0,

			}
		},
		onShow() {
			if (uni.getStorageSync('userStatus')) {
				let userStatus = uni.getStorageSync('userStatus')
				this.change(userStatus)
			} else {
				this.moneyReq()
			}
		},
		onLoad() {
			//#ifdef H5
			this.wxCofing()
			// #endif
		},
		methods: {
			async wxCofing() {
				jWeixin = require('jweixin-module');
				var uri = window.location.href.split('#')[0]; //获取当前url然后传递给后台获取授权和签名信息  
				let res = await this.$request('wechat/config', {
					url: uri
				}, 'get')
				jWeixin.config({
					debug: false,
					appId: res.appId,
					timestamp: res.timestamp,
					nonceStr: res.nonceStr,
					signature: res.signature,
					jsApiList: ["getLocation", "chooseWXPay", "requestMerchantTransfer"]
				})
			},
			async change(e) {
				let res = await this.$request('pay/selectTransferAccounts', {
					id: e
				})
				uni.removeStorageSync('userStatus')
				this.moneyReq()
			},
			goBill() {
				uni.navigateTo({
					url: '/pages/shouyi/shouyi'
				})
			},
			anyMoney() {
				if(this.money>this.data){
					uni.showToast({
						title:'提现金额不能大于余额',
						icon:'none'
					})
					return false
				}
				if(this.money<20){
					uni.showToast({
						title:'提现金额不能少于20元',
						icon:'none'
					})
					return false
				}
				let that = this
				this.$request("pay/withdrawal", {
					money: this.money
				}).then(res => {
					console.log(res,'pay/withdrawal')
					if(res.data.code==500){
						uni.showToast({
							title:res.data.msg,
							icon:'none'
						})
						return false
					}
					let mood = res.data.data
					// #ifdef MP-WEIXIN
					if (wx.canIUse('requestMerchantTransfer')) {
						wx.requestMerchantTransfer({
							mchId: mood.mchId,
							appId: 'wx86ad7950e07218a5',
							package: mood.packageInfo,
							success: (res) => {
								// res.err_msg将在页面展示成功后返回应用时返回ok，并不代表付款成功
								let cont = mood.id
								uni.setStorageSync("userStatus", cont)
							},
							fail: (res) => {
								let cont = mood.id
								uni.setStorageSync("userStatus", cont)
							},
						});
					} else {
						wx.showModal({
							content: '你的微信版本过低，请更新至最新版本。',
							showCancel: false,
						});
					}
					// #endif
					//#ifdef H5
					if (this.$jwx && this.$jwx.isWechat()) { //检查是否是微信环境
						jWeixin.ready(function() {
							jWeixin.checkJsApi({
								jsApiList: ['requestMerchantTransfer'],
								success: function(res) {
									if (res.checkResult['requestMerchantTransfer']) {
										WeixinJSBridge.invoke('requestMerchantTransfer', {
												mchId: mood.mchId,
												appId: 'wx8c726aef4a4b511a',
												package: mood.packageInfo,
											},
											function(res) {
												let cont = mood.id
												uni.setStorageSync("userStatus",cont)
											}
										);
									} else {
										alert('你的微信版本过低，请更新至最新版本。');
									}
								}
							});
						});
					}
					// #endif

				})
			},
			moneyReq() { //获取数据
				this.$request("kehu/user/myWallet",{},'get').then(res => {
					console.log(res,'kehu/user/myWallet');
					this.data = res.data;
				})
			},
		}
	}
</script>

<style>




</style>